// stores/publicInfo.js 定义一些全局参数变量
import { defineStore } from "pinia";
import { useUserStore } from "./userInfo";
import { ROOT_ID } from "@/utils/organizationConfig";
import utils from "@/utils/utils";
//通用查询日期 设置为昨天
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
export const usePublicStore = defineStore("publicInfo", {
  state: () => {
    return {
      searchDateStr: utils.formatDate(yesterday, "yyyyMMdd", true), //查询日期
      organizationId: ROOT_ID, //记录当前组织架构id
      reportId: "", //汇报人id
      isMobile: utils.isMobile(),//是否是移动端
    };
  },
  getters: {
    //当前汇报人id
    currentReportId() {
      const userStore = useUserStore();
      return this.reportId ? this.reportId : userStore.userid;
    },
  },
  actions: {
    setOrganizationId(organizationId) {
      this.organizationId = organizationId;
    },
    setReportId(reportId) {
      this.reportId = reportId;
    },
  },
  //   persist: true,
  persist: {
    //持久化指定内容
    pick: ["organizationId", "reportId"],
    storage: sessionStorage,
  },
});
